package bank;

import java.util.HashMap;

public class _01TwoSum {
    public static int[] twoSum(int[] nums, int target) {
        int[] indexs = new int[2];
        HashMap<Integer,Integer> hashMap = new HashMap<>();
        for(int i = 0;i < nums.length;i++){
            if(hashMap.containsKey(nums[i])){
                indexs[0] = i;
                indexs[1] = hashMap.get(nums[i]);
                return indexs;
            }
            //key值为所需要的下一个数，一旦在遍历的时候发现有存在该数字则取出二者下标！
            hashMap.put(target-nums[i],i);
        }
        return indexs;
    }
}
